package com.tarena.lbs.content.service.impl;

import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.common.utils.PageConverter;
import com.tarena.lbs.content.dao.repository.CategoryRepository;
import com.tarena.lbs.content.pojo.po.ArticleCategoryPO;
import com.tarena.lbs.content.pojo.vo.ArticleCategoryVO;
import com.tarena.lbs.content.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
/**
 * @author 周恒宇
 * @date 6/10
 */
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryRepository categoryRepository;


    @Override
    public PageResult<ArticleCategoryVO> pageList() {
        PageInfo<ArticleCategoryPO> info = categoryRepository.pageList();
        List<ArticleCategoryPO> list = info.getList();
        List<ArticleCategoryVO> articleCategoryVOS = new ArrayList<>();
        for (ArticleCategoryPO articleCategoryPO : list) {
            ArticleCategoryVO articleCategoryVO = new ArticleCategoryVO();
            BeanUtils.copyProperties(articleCategoryPO,articleCategoryVO);
            articleCategoryVOS.add(articleCategoryVO);
        }
        return PageConverter.convert(info,articleCategoryVOS);
    }
}
